home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UInsertPartCommand.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  5.9 KB  |  234 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UInsertPartCommand.cp
  3. // Copyright © 1994-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UINSERTPARTCOMMAND__
  7. #include "UInsertPartCommand.h"
  8. #endif
  9.  
  10. #if qContainer
  11.  
  12. #ifndef __UODPARTVIEW__
  13. #include "UODPartView.h"
  14. #endif
  15.  
  16. // MacApp
  17.  
  18. #ifndef __UCLIPBOARDMGR__
  19. #include "UClipboardMgr.h"
  20. #endif
  21.  
  22. #ifndef __UMACAPPGLOBALS__
  23. #include "UMacAppGlobals.h"
  24. #endif
  25.  
  26. #ifndef __UMACAPPUTILITIES__
  27. #include "UMacAppUtilities.h"
  28. #endif
  29.  
  30. #ifndef __UMEMORY__
  31. #include "UMemory.h"
  32. #endif
  33.  
  34. #ifndef __UWINDOW__
  35. #include "UWindow.h"
  36. #endif
  37.  
  38. // CALib
  39.  
  40. #if qContainer
  41.     #ifndef _CALIB_
  42.     #include "CALib.h"
  43.     #endif
  44. #endif
  45.  
  46. // Toolbox
  47.  
  48. #ifndef __STANDARDFILE__
  49. #include <StandardFile.h>
  50. #endif
  51.  
  52. #ifndef __STDLIB__
  53. #include <stdlib.h>
  54. #endif
  55.  
  56. //========================================================================================
  57. // CLASS TInsertPartCommand
  58. //========================================================================================
  59. #undef Inherited
  60. #define Inherited TCommand
  61.  
  62. #pragma segment ASelCommand
  63. MA_DEFINE_CLASS_M1(TInsertPartCommand, Inherited);
  64.  
  65. //----------------------------------------------------------------------------------------
  66. // Constructor
  67. //----------------------------------------------------------------------------------------
  68. #pragma segment ASelCommand
  69.  
  70. TInsertPartCommand::TInsertPartCommand()
  71.     : fODPartView(NULL),
  72.       fDocument(NULL)
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // Destructor
  78. //----------------------------------------------------------------------------------------
  79. #pragma segment MADestructorRes
  80.  
  81. TInsertPartCommand::~TInsertPartCommand()
  82. {
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // TInsertPartCommand::IInsertPartCommand
  87. //----------------------------------------------------------------------------------------
  88. #pragma segment ASelCommand
  89.  
  90. Boolean TInsertPartCommand::IInsertPartCommand(CommandNumber itsCommandNumber,
  91.                                                TDocument* itsDocument,
  92.                                                TODPartView* itsPartView)
  93. {
  94.     Boolean  fileChosen = ChoosePartFile();
  95.     if (fileChosen)
  96.     {
  97.         this->ICommand(itsCommandNumber, itsDocument,
  98.                          kCanUndo, kCausesChange, itsDocument);
  99.         fDocument = itsDocument;
  100.         fODPartView = itsPartView;
  101.     }
  102.     
  103.     return fileChosen;
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // TInsertPartCommand::DoIt()
  108. //----------------------------------------------------------------------------------------
  109. #pragma segment ADoCommand
  110.  
  111. void TInsertPartCommand::DoIt()
  112. {
  113.     
  114.     if (fODPartView)
  115.     {
  116.         
  117.         //Remove the old part.
  118.         if(fODPartView->HasPart())
  119.         {
  120.             fODPartView->RemovePart();
  121.         }
  122.         
  123.         // IF THERE IS NO fODPartView, make one. for now, upper left? •••
  124.         //if(!fODPartView)
  125.         //fODPartView = new
  126.         
  127.         fODPartView->AquirePartFromFile(fFileSpec);
  128.     }
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // TInsertPartCommand::UndoIt()
  133. //----------------------------------------------------------------------------------------
  134. #pragma segment ADoCommand
  135.  
  136. void TInsertPartCommand::UndoIt()
  137. {
  138.     if(fODPartView->HasPart())
  139.     {
  140.         fODPartView->RemovePart();
  141.     }
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // TInsertPartCommand::RedoIt()
  146. //----------------------------------------------------------------------------------------
  147. #pragma segment ADoCommand
  148.  
  149. void TInsertPartCommand::RedoIt()
  150. {
  151.     this->DoIt();
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // TInsertPartCommand::ChoosePartFile
  156. //----------------------------------------------------------------------------------------
  157. #pragma segment ASelCommand
  158.  
  159. Boolean TInsertPartCommand::ChoosePartFile()
  160. {
  161.     FailOSErr(MAInteractWithUser()); 
  162.     gClipboardMgr->AboutToLoseControl(TRUE);            // so scrap gets converted
  163.  
  164.     Boolean                done = FALSE;
  165.  
  166.     // Insure we can go modal at this time.
  167.     WindowPtr        frontWindow = CAGetFrontDocWindow();
  168.     if (CARequestModalFocus(frontWindow))
  169.     {
  170.         StandardFileReply    customReply;
  171.         FileFilterYDUPP        cgfFileFilter = NewFileFilterYDProc(TInsertPartCommand::PartFileFilter);
  172.         ModalFilterYDUPP     cgfModalFilter = NewModalFilterYDProc(gModalFilterYDProcPtr);
  173.  
  174.         CustomGetFile(cgfFileFilter,
  175.                         -1,                // Pass all file types
  176.                         NULL,            // No type list
  177.                         &customReply,
  178.                         sfGetDialogID,
  179.                         kBestSystemLocation,
  180.                         NULL,            // Dialog hook function
  181.                         cgfModalFilter,
  182.                         NULL,            // Activate list
  183.                         NULL,            // Activate proc
  184.                         NULL);
  185.  
  186.         CARelinquishModalFocus(frontWindow);
  187.     
  188.         if (customReply.sfGood)
  189.         {
  190.             fFileSpec = customReply.sfFile;
  191.             done = TRUE;
  192.         }
  193.     }
  194.     return done;    
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. // TInsertPartCommand::PartFileFilter
  199. //----------------------------------------------------------------------------------------
  200. #pragma segment ASelCommand
  201.  
  202. pascal Boolean TInsertPartCommand::PartFileFilter(CInfoPBPtr pb)
  203. {
  204.     HFileInfo*    fpb = (HFileInfo*)pb;
  205.  
  206.     if (!(fpb->ioFlAttrib & 16))
  207.     {
  208.         return (!(fpb->ioFlFndrInfo.fdCreator == kODShellSignature) &&
  209.             (fpb->ioFlFndrInfo.fdType != 'APPL') &&
  210.             (fpb->ioFlFndrInfo.fdType != 'shlb'));
  211.     }
  212.     return false;
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. // TInsertPartCommand::Commit
  217. //----------------------------------------------------------------------------------------
  218. #pragma segment ADoCommand
  219.  
  220. void TInsertPartCommand::Commit()
  221. {
  222.     if (!fCommandDone && fODPartView)
  223.     {
  224.         fODPartView = (TODPartView*)FreeIfObject(fODPartView);
  225.     }
  226. }
  227.  
  228. #endif // qContainer
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // End of UInsertPartCommand.cp
  232.  
  233. #pragma segment Inline
  234.